﻿using MY.ShoppingBackstage.BLL;
using MY.ShoppingBackstage.Model;
using MY.ShoppingBackstage.Models;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace MY.ShoppingBackstage.Controllers
{
    public class MemberController : Controller
    {
        UserInfoService userInfoService = new UserInfoService();

        /// <summary>
        /// 会员列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Member_List(string name)
        {
            
            List<UAddress> address = userInfoService.GetQuery(name);
            ViewBag.address = address;
            List<UAddress> address2= userInfoService.GetAddress();
            address2[0].ProvinceName = "浙江省";
            address2[1].ProvinceName = "安徽省";
            address2[2].ProvinceName = "陕西省";

            address2[0].CityName = "宁波市";
            address2[1].CityName = "铜陵市";
            address2[2].CityName = "西安市";

            address2[0].DistrictName = "鄞州区";
            address2[1].DistrictName = "洛阳城";
            address2[2].DistrictName = "长安城";

            ViewBag.GetAddress = address2;
            return View();
            
        }

        /// <summary>
        /// 获取管理员列表（分页）
        /// </summary>
        /// <param name="page">页码</param>
        /// <param name="limit">每页查询数</param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetPageList(int page, int limit,string name)
        {
            if (name == null)
            {
                name = "";
            }
            List<UAddress> uAddresses = userInfoService.GetQuery(name);
            PageListResult<UAddress> pageList = new PageListResult<UAddress>();
            pageList.code = 0;
            pageList.msg = string.Empty;
            pageList.data = uAddresses.Skip((page - 1) * limit).Take(limit).ToList();
            pageList.count = uAddresses.Count;
            return Json(pageList, JsonRequestBehavior.AllowGet);
        }



        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="id">用户id</param>
        /// <returns></returns>
        public JsonResult DeleteUser(int id)
        {
            OperateResult operateResult = new OperateResult();
            operateResult.Success = userInfoService.DeleteUser(id);
            return Json(operateResult);
        }


        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="uAddress">用户地址表</param>
        /// <returns></returns>
        public JsonResult UpdateUser(UAddress uAddress)
        {
            OperateResult operateResult = new OperateResult();
            operateResult.Success = userInfoService.UpdateUser(uAddress);
            return Json(operateResult);
        }


        /// <summary>
        /// 修改状态（禁用/启用）
        /// </summary>
        /// <param name="Uid">用户Id</param>
        /// <param name="Status">状态</param>
        /// <returns></returns>
        public JsonResult UpdateStatus(int Uid, int Status)
        {
            OperateResult operateResult = new OperateResult();
            operateResult.Success = userInfoService.UpdateStatus(Uid,Status);
            return Json(operateResult);
        }


    }
}